package com.shebao.service;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shebao.dao.SBPersonDao;
import com.shebao.entity.SBPersonEntity;

@Service
public class DataService {
	@Autowired
	private SBPersonDao sbPersonDao;
	
	public void data(){
		List<SBPersonEntity> list=sbPersonDao.list();
		SBPersonEntity entity=null;
		for(int i=0;i<list.size();i++){
			System.out.println("处理第"+i+"条数据---------");
			entity=list.get(i);
			
			entity.setOldBase(checkData(entity.getOldBase()));
			entity.setOldCompany(checkData(entity.getOldCompany()));
			entity.setOldPerson(checkData(entity.getOldPerson()));
			
			entity.setMedicalBase(checkData(entity.getMedicalBase()));
			entity.setMedicalCompany(checkData(entity.getMedicalCompany()));
			entity.setMedicalPerson(checkData(entity.getMedicalPerson()));
			
			entity.setSupplyBase(checkData(entity.getSupplyBase()));
			entity.setSupplyCompany(checkData(entity.getSupplyCompany()));
			entity.setSupplyPerson(checkData(entity.getSupplyPerson()));
			
			entity.setBirthBase(checkData(entity.getBirthBase()));
			entity.setBirthCompany(checkData(entity.getBirthCompany()));
			entity.setBirthPerson(checkData(entity.getBirthPerson()));
			
			entity.setUnemploymentBase(checkData(entity.getUnemploymentBase()));
			entity.setUnemploymentCompany(checkData(entity.getUnemploymentCompany()));
			entity.setUnemploymentPerson(checkData(entity.getUnemploymentPerson()));
			
			entity.setHurtBase(checkData(entity.getHurtBase()));
			entity.setHurtCompany(checkData(entity.getHurtCompany()));
			
			sbPersonDao.update(entity);
		}
	}
	
	public void add(){
		List<SBPersonEntity> list=sbPersonDao.listPayDate("201710");
		for(SBPersonEntity sb:list){
			SBPersonEntity e1=new SBPersonEntity();
			BeanUtils.copyProperties(sb,e1);
			e1.setPayDate("201711");
			SBPersonEntity e2=new SBPersonEntity();
			BeanUtils.copyProperties(sb,e2);
			e2.setPayDate("201712");
			sbPersonDao.add(e1);
			sbPersonDao.add(e2);
		}
	}
	
	
	private String checkData(String source){
		source=source.trim();
		if(source.length()==0){
			return "";
		}
		String[] ss=source.split("\\.");
		if(1==ss.length){
			if(source.endsWith(".")){
				String aa=source+"00";
				return aa;
			}else{
				String a=source+".00";
				return a;
			}
		}else{
			String temp=ss[1];
			if(1==temp.length()){
				String b=source+"0";
				return b;
			}else{
				return source;
			}
		}
	}
	
}
